import express from "express";
import morgan from "morgan";
import fs from "node:fs";
import path from "node:path";
import router from "./router/index.js";
import "./model/index.js";

const app = express();
const port = process.env.PORT || 3000;

app.use(
  morgan("combined", {
    stream: fs.createWriteStream(path.join(process.cwd(), "logs", "access.log"), {
      flags: "a",
    }),
  }),
);
// 注册静态资源中间件
app.use(express.static(path.join(process.cwd(), "/public")));
// 注册处理请求体中间件
app.use(express.json());
// 注册路由中间件
app.use("/api/v1", router);

app.listen(port, () => {
  console.log(`Server listening on port ${port}`);
});

